package com.tensquare.qa.service;

import com.tensquare.qa.dao.QaDao;
import com.tensquare.qa.pojo.Problem;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by WF on 2020/3/30 15:44
 */
@Service
public class QaService {
    @Autowired
    private QaDao qaDao;
    //1.查询最新问题列表
    public PageResult newList(String labelid, int page, int size) {
        //1.1)查询最新问题列表
        Page<Problem> problemPage = qaDao.findProblemsByLabelid(labelid, PageRequest.of(page - 1, size));
        //1.2)返回
        return new PageResult(problemPage.getTotalElements(),problemPage.getContent());
    }
    //2.查询热门问题
    public PageResult hotlist(String labelid, int page, int size) {
        //2.1)查询热门问题
        Page<Problem> problemPage = qaDao.findHotListByLabelId(labelid,PageRequest.of(page-1,size));
        //2.2)返回
        return new PageResult(problemPage.getTotalElements(),problemPage.getContent());
    }
}
